extern crate net_brd;
use net_brd::Chain;
use net_brd::ChainData;
use net_brd::Task;
use log;
use net_brd::net;
use net_brd::Color;

fn main() {
    let my_ip = net::who_am_i();
    println!("{}", my_ip);    
    let mut b = Chain::default();
    let sub_one = Chain::default();
    b.insert(&sub_one);
    let id = b.save();
    
    log::info!("this brd json: {}", b.to_json().green());
    log::info!("{}",id.green());
    
    if let Some(b2) = id.chain_load(){
        log::info!("{}", b2);
    
        let id = b2.save_pwd("hello");
        if let Some(b2) = format!("{}||{}",id,"error_pwd").chain_load(){
            log::info!("with pwd:{} | {}", "hello",b2);
            b2.loc.uid.chain_remove();
        }
        if let Some(b2) = format!("{}||{}",id,"hello").chain_load(){
            log::info!("with pwd:{} | {}", "hello",b2);
            b2.loc.uid.chain_remove();
        }
    };

    let test_default_task = Task::default();
    log::info!("default taks: {}", test_default_task);
    let mut task  = "cmd://curl@".push_args(&vec!["https://www.baidu.com", "https://www.douban.com"]);
    task.push_str("->1");
    log::info!("generate taks by str : {}", &task);
    if let Some(b_task) = task.to_task(){
        log::info!("task : {}", &b_task);
        let bb = b_task.new_chain();
        log::info!("task -> chain : {}", &bb);

        let id = bb.save_pwd("what?");
        if let Some(bb_l) = id.chain_load_pwd("what?"){
            log::info!("load ok : {}", bb_l);
            log::info!("json :\n{}", bb_l.to_json());
            bb_l.loc.uid.chain_remove();
        }

    }


    
}